import project from '@/lib/request/project'
import { RootState } from '../index'
import { Commit } from 'vuex'
import { IResponse } from '@/lib/service'

export interface ProjectState {}
const initState: ProjectState = {}

const getters = {}

const actions = {
  authorizeAllManageSeal(
    context: {
      commit: Commit
      state: ProjectState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    // 授权全部印章
    return project
      .authorizeAllManageSeal(payload)
      .then((data: IResponse) => data.data)
  },
  authorizeManageSeal(
    context: {
      commit: Commit
      state: ProjectState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    // 授权印章
    return project
      .authorizeManageSeal(payload)
      .then((data: IResponse) => data.data)
  },
  cancelAuthorizeAllManageSeal(
    context: {
      commit: Commit
      state: ProjectState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    // 取消授权所有印章
    return project
      .cancelAuthorizeAllManageSeal(payload)
      .then((data: IResponse) => data.data)
  },

  cancelAuthorizeManageSeal(
    context: {
      commit: Commit
      state: ProjectState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    // 取消授权印章
    return project
      .cancelAuthorizeManageSeal(payload)
      .then((data: IResponse) => data.data)
  },
  queryManageSeal(
    context: {
      commit: Commit
      state: ProjectState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    // 根据projectId的授权印章（所有）包含未授权
    return project.queryManageSeal(payload).then((data: IResponse) => data.data)
  },
  queryManageSealProjectAuthorizeSeal(
    context: {
      commit: Commit
      state: ProjectState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    // 抽屉查询应用授权印章
    return project
      .queryManageSealProjectAuthorizeSeal(payload)
      .then((data: IResponse) => data.data)
  },
  queryManageSealProjectAuthorizeSealsCount(
    context: {
      commit: Commit
      state: ProjectState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    // 抽屉查询应用授权印章数量
    return project
      .queryManageSealProjectAuthorizeSealsCount(payload)
      .then((data: IResponse) => data.data)
  },
  queryProjectManageSealAuthorizeList(
    context: {
      commit: Commit
      state: ProjectState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    // 查询所有管理印章授权的应用
    return project
      .queryProjectManageSealAuthorizeList(payload)
      .then((data: IResponse) => data.data)
  },
  queryProjectSimplesBySealUseType(
    context: {
      commit: Commit
      state: ProjectState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    // 查询所有管理印章授权的应用
    return project
      .queryProjectSimplesBySealUseType(payload)
      .then((data: IResponse) => data.data)
  },
  copyAuthorizeManageSeal(
    context: {
      commit: Commit
      state: ProjectState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return project
      .copyAuthorizeManageSeal(payload)
      .then((data: IResponse) => data.data)
  },
  queryProjectDeail(
    context: {
      commit: Commit
      state: ProjectState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return project
      .queryProjectDeail(payload)
      .then((data: IResponse) => data.data)
  },
  queryProjectManageSealAuthorizeListBySeal(
    context: {
      commit: Commit
      state: ProjectState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return project
      .queryProjectManageSealAuthorizeListBySeal(payload)
      .then((data: IResponse) => data.data)
  },
  authorizeManageSealToProject(
    context: {
      commit: Commit
      state: ProjectState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return project
      .authorizeManageSealToProject(payload)
      .then((data: IResponse) => data.data)
  },
  authorizeManageSealToAllProject(
    context: {
      commit: Commit
      state: ProjectState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return project
      .authorizeManageSealToAllProject(payload)
      .then((data: IResponse) => data.data)
  },
  cancelAuthorizeManageSealToProject(
    context: {
      commit: Commit
      state: ProjectState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return project
      .cancelAuthorizeManageSealToProject(payload)
      .then((data: IResponse) => data.data)
  },
  cancelAuthorizeManageSealToAllProject(
    context: {
      commit: Commit
      state: ProjectState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return project
      .cancelAuthorizeManageSealToAllProject(payload)
      .then((data: IResponse) => data.data)
  },
  queryProjectSimplesBySealUseTypeBySeal(
    context: {
      commit: Commit
      state: ProjectState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    return project
      .queryProjectSimplesBySealUseTypeBySeal(payload)
      .then((data: IResponse) => data.data)
  },

  queryManageSealAuthorizeCountBySeal(
    context: {
      commit: Commit
      state: ProjectState
      rootState: RootState
      getters: any
    },
    payload: any
  ) {
    // 抽屉查询印章授权应用数量
    return project
      .queryManageSealAuthorizeCountBySeal(payload)
      .then((data: IResponse) => data.data)
  },
}

const mutations = {
  setStateData(state: ProjectState, data: any) {
    // eslint-disable-next-line no-param-reassign
    state = Object.assign(state, data)
  },
}

export default {
  namespaced: true,
  state: initState,
  getters,
  actions,
  mutations,
}
